﻿using System;
using System.Collections.Generic;
using Authority.Logic;
using Authority.Model;
using Common.Library;
using Container.Library;
using Microsoft.AspNetCore.Mvc;
using Tool.Model;
using Web.Manage.App_Start;

namespace Web.Manage.Areas.Authority.Controllers
{
    /// <summary>
    /// 岗位功能管理
    /// </summary>
    [Area("Authority")]
    public class PostController : BaseController
    {
        private readonly ISysPostService postService = null;//岗位功能管理逻辑
        public PostController()
        {
            //岗位功能管理逻辑注入
            postService = UnityCIContainer.Instance.GetService<ISysPostService>();
        }

        #region 界面
        /// <summary>
        /// 列表界面
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyView)]
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        ///新增界面
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyLoggedIn)]
        public ActionResult Add()
        {
            return View();
        }


        /// <summary>
        /// 编辑界面
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyLoggedIn)]
        public ActionResult Modify()
        {
            return View();
        }
        #endregion

        #region 查询操作
        /// <summary>
        /// 分页获取所有的可操作按钮
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyLoggedIn)]
        public ActionResult LoadListInfo()
        {
            var resultInfo = new ResultJsonInfo<List<SysPostEntity>>();
            try
            {
                //实体接收数据
                var parametersInfo = DeserializeRequestData<ParametersInfo<string>>();

                resultInfo = postService.LoadSysPostList(parametersInfo);
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Excep = ex;
            }
            return ReturnContent(resultInfo);
        }


        /// <summary>
        /// 获取所有的岗位列表信息
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyLoggedIn)]
        public ActionResult LoadPostSelectList()
        {

            var resultInfo = new ResultJsonInfo<List<SelectListInfo>>();
            try
            {
                resultInfo = postService.LoadSysPostAllList();
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Msg = ex.Message;
            }
            return ReturnContent(resultInfo);
        }
        #endregion

        #region 增加信息
        /// <summary>
        /// 增加信息
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyAction, ButtonAuthorizationCode.Add)]
        public ActionResult AddInfo()
        {
            var resultInfo = new ResultJsonInfo<int>();
            try
            {
                //实体接收数据
                var parametersInfo = DeserializeRequestData<ParametersInfo<PostOperateRequest>>();

                resultInfo = postService.Save(parametersInfo.parameters);
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Excep = ex;
            }
            return ReturnContent(resultInfo);
        }
        #endregion

        #region 修改信息
        /// <summary>
        /// 修改信息
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyAction, ButtonAuthorizationCode.Edit)]
        public ActionResult ModifyInfo()
        {
            var resultInfo = new ResultJsonInfo<int>();
            try
            {
                //实体接收数据
                var parametersInfo = DeserializeRequestData<ParametersInfo<PostOperateRequest>>();

                resultInfo = postService.Save(parametersInfo.parameters);
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Excep = ex;
            }
            return ReturnContent(resultInfo);
        }
        #endregion

        #region 删除信息
        /// <summary>
        /// 删除信息
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyAction, ButtonAuthorizationCode.Remove)]
        public ActionResult Remove()
        {
            var resultInfo = new ResultJsonInfo<int>();
            try
            {
                //实体接收数据
                var parametersInfo = DeserializeRequestData<ParametersInfo<List<string>>>();

                resultInfo = postService.Remove(parametersInfo.parameters);
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Excep = ex;
            }
            return ReturnContent(resultInfo);
        }
        #endregion

    }
}